﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Entities;
using ExpertMIS.Brokers;
using System.Collections;

namespace ExpertMIS.Admin.UserControl
{
    public partial class IdiomForm : System.Web.UI.UserControl
    {
        #region 控件事件处理

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #endregion

        #region 公有方法


        public ADMIDIOMEntity Entity
        {
            get
            {
                return ViewState["_ADMIDIOMEntity_"] as ADMIDIOMEntity;
            }
            set
            {
                ViewState["_ADMIDIOMEntity_"] = value;
            }
        }

        public void LoadIdiom(string columnOID)
        {
            ADMIDIOMBroker broker = new ADMIDIOMBroker();

            Hashtable htQuery = new Hashtable();
            htQuery["OID"] = columnOID;
            Entity = broker.GetEntity(htQuery) as ADMIDIOMEntity;

            if (Entity == null)
            {
                Entity = broker.NewEntity() as ADMIDIOMEntity;
            }
            else
            {
                txContent.Text = Entity.Content;
                rblIsPassed.SelectedValue = Entity.Enable.Value ? "true" : "false";
            }
        }

        public bool SaveIdiom()
        {
            try
            {
                ADMIDIOMBroker broker = new ADMIDIOMBroker();

                Entity.Content = txContent.Text;
                Entity.Enable = bool.Parse(rblIsPassed.SelectedValue);

                broker.SaveEntity(Entity, null);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }
}